package com.mojo.io.prop;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Properties;
import java.util.Set;

/**
 * io相关的集合Properties，常用于读取配置文件
 *
 * @author <a href="mailto:mojo_jj@163.com">Mojo</a>
 */
public class Properties1 {
    public static void main(String[] args) throws IOException {
        test1();
    }

    private static void test1() throws IOException {
        Properties prop1 = new Properties();
        prop1.setProperty("mojo", "dfasd");
        Properties prop = new Properties(prop1);
        FileReader fileReader = new FileReader("E:\\project\\a.txt");
        File file = new File("E:\\project\\a.txt");
        FileInputStream fileInputStream = new FileInputStream(file);

        byte[] bytes = new byte[1024];
        int read = 0;
        while ((read = fileInputStream.read(bytes)) > 0) {
            String s = new String(bytes, 0, read, StandardCharsets.UTF_8);
            System.out.println(s);
        }
        fileInputStream.close();
        System.out.println(">>>>>");
        prop.load(fileReader);
        Set<String> strings = prop.stringPropertyNames();
        for (String string : strings) {
            System.out.println(string + "=" + prop.getProperty(string));
        }
        fileReader.close();
    }
}
